package com.gotrade.springbootexceptiondemo.controller;

import com.gotrade.springbootexceptiondemo.model.Result;
import com.gotrade.springbootexceptiondemo.model.User;
import com.gotrade.springbootexceptiondemo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author jason.tang
 * @create 2019/4/28
 * @description 用户控制器
 */
@Api(tags = "用户")
@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "根据userNum获取用户信息", notes = "根据userNum获取用户信息")
    @ApiImplicitParam(name = "userNum", value = "用户编号", required = true, dataType = "int", paramType = "path")
    @GetMapping("/{userNum}")
    public Result<User> getUserByNum(@PathVariable Integer userNum) {
        return Result.success(userService.getUserByNum(userNum));
    }


    @ApiOperation(value = "新增用户", notes = "新增用户")
    @ApiImplicitParam(name = "user", value = "用户实体", required = true, dataType = "User")
    @PostMapping("")
    public Result<User> addUser(@RequestBody User user) {
        return Result.success(userService.addUser(user));
    }
}
